﻿using System;
using Dsl.Ped.Common.Helpers;
using NUnit.Framework;

namespace DSLPedCommonTest.Helpers
{
    [TestFixture]
    public class LanguageUtilsTest
    {
        [SetUp]
        public void SetUpForEachTest()
        {
            // Not used section
        }

        [Test]
        public void GetClassNameFromFile1()
        {
            const string filePath = "test.cs";
            string result = LanguageHelper.GetClassNameFromFile(filePath);

            Assert.AreEqual("test", result);
        }

        [Test]
        public void GetClassNameFromFile2()
        {
            const string filePath = "C:/Program Files/Pokus/test.cs";
            string result = LanguageHelper.GetClassNameFromFile(filePath);

            Assert.AreEqual("test", result);
        }

        [Test]
        public void GetClassNameFromFile3()
        {
            const string filePath = @"C:\Program Files\Pokus\test.cs";
            string result = LanguageHelper.GetClassNameFromFile(filePath);

            Assert.AreEqual("test", result);
        }

        [Test]
        public void GetClassNameFromFile4()
        {
            const string filePath = "C:\\Program Files\\Pokus\\test.ext";
            string result = LanguageHelper.GetClassNameFromFile(filePath);

            Assert.AreEqual("test", result);
        }

        [Test]
        public void GetClassNameFromFile5()
        {
            const string filePath = "C:\\Program Files\\Pokus\\test.ext.cs";
            string result = LanguageHelper.GetClassNameFromFile(filePath);

            Assert.AreEqual("test.ext", result);
        }

        [Test]
        public void GetNamespaceFromFile1()
        {
            const string defaultNamespace = "my.namespace.xyz";
            const string relativeFilePath = "Projections\\Custom\\DSLPedProj1.proj";

            string result = LanguageHelper.GetNamespaceFromFile(defaultNamespace, relativeFilePath);

            Assert.AreEqual("my.namespace.xyz.Projections.Custom", result);
        }

        [Test]
        public void GetNamespaceFromFile2()
        {
            try
            {
                const string defaultNamespace = "";
                const string relativeFilePath = "Projections\\Custom\\DSLPedProj1.proj";

                string result = LanguageHelper.GetNamespaceFromFile(defaultNamespace, relativeFilePath);
            } catch (ArgumentException exc)
            {
                // OK, the ArgumentException has been expected
            }
        }

        [Test]
        public void GetNamespaceFromFile3()
        {
            const string defaultNamespace = "my.namespace.xyz";
            const string relativeFilePath = @"Projections\Custom\DSLPedProj1.proj";

            string result = LanguageHelper.GetNamespaceFromFile(defaultNamespace, relativeFilePath);

            Assert.AreEqual("my.namespace.xyz.Projections.Custom", result);
        }

        [Test]
        public void GetNamespaceFromFile4()
        {
            const string defaultNamespace = "my.namespace.xyz";
            const string relativeFilePath = "DSLPedProj1.proj";

            string result = LanguageHelper.GetNamespaceFromFile(defaultNamespace, relativeFilePath);

            Assert.AreEqual("my.namespace.xyz", result);
        }
    }
}
